/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package androidpos.util;

import androidpos.db.ConnectToDB;
import androidpos.gui.TransactionPanel;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Date;

/**
 *
 * @author user
 */
public class TransactionHandler {
    private TransactionPanel transactionPanel;
    private javax.swing.JTextArea logArea;
    private Connection connection;
    public TransactionHandler(TransactionPanel transactionPanel) {
        this.transactionPanel = transactionPanel;
        logArea = transactionPanel.getLogArea();
        connection = new ConnectToDB().getConnection();
    }
   public void insertToTransaction(String payerName , String totalPrice , String unit){
       String now = new Date().toString();
       String logText = ""+
               "-------New transaction--------\n" +
               "Payer : "+payerName+"\n"+
               "Total : "+totalPrice+" "+unit+"\n" +
               "Time  : "+now+"\n" +
               "------------------------------\n";
       try{
           Statement st = connection.createStatement();
           st.executeUpdate("INSERT INTO purchase_header (payer_name,total_price,unit) " +
                   "VALUES ('"+payerName+"',"+totalPrice+",'"+unit+"');");
       }catch(Exception e){
           
       }
       
       logArea.setText(logArea.getText()+logText+"\n");
       logArea.setCaretPosition(logArea.getText().length()-1);
   }
    
}
